package p05_Stack;

import java.util.Arrays;
import java.util.Scanner;

public class P1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        boolean flag = true;
        ArrayStack stack = new ArrayStack(4);
        System.out.println("开始运行，请输入指令：");
        while (flag) {
            String key = scanner.next();
            int value;
            switch (key) {
                case "push":
                    value = scanner.nextInt();
                    stack.push(value);
                    break;
                case "pop":
                    try {
                        System.out.println(stack.pop());
                    } catch (Exception e) {
                        System.out.println(e.getMessage());
                    }
                    break;
                case "print":
                    stack.print();
                    break;
                case "exit":
                    flag = false;
                    scanner.close();
                    break;
            }
        }
    }
}
